<template>
  <div style="height: 400px">
    <!-- swiper1 -->
    <swiper :options="swiperOptionTop" class="gallery-top" ref="swiperTop">
      <swiper-slide v-for="(item,index) in listImg" :key="index">
        <img class="swiper-image border" :src="item.url" alt="swiper-image">
      </swiper-slide>
      <div class="swiper-button-next swiper-button-white" slot="button-next"></div>
      <div class="swiper-button-prev swiper-button-white" slot="button-prev"></div>
    </swiper>
    <swiper :options="swiperOptionThumbs" class="gallery-thumbs" ref="swiperThumbs">
      <swiper-slide v-for="(item,index) in listImg" :key="index">
        <img class="swiper-image" :src="item.url" alt="swiper-image">
      </swiper-slide>
    </swiper>
  </div>
</template>


<script>
  import 'swiper/dist/css/swiper.css';
  import {
    swiper,
    swiperSlide
  } from 'vue-awesome-swiper';
  export default {
    components: {
      swiper,
      swiperSlide
    },
    props: {
      listImg: {
        type: Array,
        default: []
      },
      mystyle: {
        type: String,
        default: ''
      },
      iscover: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        swiperOptionTop: {
          spaceBetween: 10,
          loop: true,
          loopedSlides: this.$props.listImg.length, //looped slides should be the same
          navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev'
          }
        },
        swiperOptionThumbs: {
          spaceBetween: 10,
          slidesPerView: 3,
          touchRatio: 0.2,
          loop: true,
          loopedSlides: this.$props.listImg.length, //looped slides should be the same
          slideToClickedSlide: true,
        }
      };
    },
    mounted() {
      this.$nextTick(() => {
        const swiperTop = this.$refs.swiperTop.swiper;
        const swiperThumbs = this.$refs.swiperThumbs.swiper;
        swiperTop.controller.control = swiperThumbs;
        swiperThumbs.controller.control = swiperTop;
      });
    }
  };

</script>

<style lang="scss" scoped>
  .swiper-container {
    background-color: #fff;
  }

  .swiper-slide {
    background-size: cover;
    background-position: center;
  }

  .gallery-top {
    height: 300px;
    width: 300px;
  }

  .gallery-top .swiper-image {
    height: 300px;
    width: 300px;
  }

  .gallery-thumbs {
    height: 100px !important;
    box-sizing: border-box;
    padding: 10px 0 2px 0px;
  }

  .gallery-thumbs .swiper-slide {
    width: 80px;
    height: 100%;
    opacity: 0.4;
  }

  .gallery-thumbs .swiper-slide img{
    width:100%;
    height:100%;
  }

  .swiper-button-prev, .swiper-button-next{
    background-size: 18px 29px;
  }

  .gallery-thumbs .swiper-slide-active {
    opacity: 1;
  }

</style>
